package com.hymall.service.admin;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hymall.bean.MarketAdmin;
import com.hymall.bean.MarketBrand;
import com.hymall.bean.MarketBrandExample;
import com.hymall.bean.common.BasePageInfo;
import com.hymall.bean.common.CommonData;
import com.hymall.bean.vo.BrandCreateVo;
import com.hymall.mapper.MarketBrandMapper;
import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author: 周子伟
 * @description ${商场管理 品牌制造商对应的 增删改查}
 * @date: 2022/7/16 23:30
 */

@Service
public class AdminBrandServiceImpl implements AdminBrandService {
    @Autowired
    MarketBrandMapper brandMapper;


    /*
     * @author Invoker
     * @description {查找品牌信息功能}
     * @date
     * @param
     * @return
     */
    @Override
    public CommonData query(String name, Integer id, BasePageInfo info) {

        PageHelper.startPage(info.getPage(), info.getLimit());
        MarketBrandExample marketBrandExample = new MarketBrandExample();
        marketBrandExample.setOrderByClause(info.getSort() + " " + info.getOrder());
        MarketBrandExample.Criteria criteria = marketBrandExample.createCriteria();
        if (name != null && !"".equals(name)) {

            criteria.andNameLike("%" + name + "%");
        }
        if (id != null) {
            criteria.andIdEqualTo(id);
        }

        List<MarketBrand> marketBrands = brandMapper.selectByExample(marketBrandExample);
        PageInfo<MarketBrand> pageInfo = new PageInfo<>(marketBrands);
        return CommonData.data(pageInfo);

    }


    /*
     * @author Invoker
     * @description { 新增品牌信息功能}
     * @date
     * @param   marketBrand
     * @return
     */
    @Override
    public BrandCreateVo create(MarketBrand marketBrand) {

        brandMapper.insertSelective(marketBrand);
        Date addtime = new Date();

        BrandCreateVo brandCreateVo = new BrandCreateVo(marketBrand.getId(), marketBrand.getName(), marketBrand.getDesc(), marketBrand.getPicUrl(), marketBrand.getFloorPrice(), addtime, addtime);
        return brandCreateVo;
    }



    /*
     * @author Invoker
     * @description {修改品牌信息功能}
     * @date
     * @param marketBrand
     * @return
     */
    @Override
    public MarketBrand update(MarketBrand marketBrand) {
        Date updatetime = new Date();
        brandMapper.updateByPrimaryKeySelective(marketBrand);
        marketBrand.setUpdateTime(updatetime);

        return marketBrand;
    }

    @Override
    public boolean delete(MarketBrand marketBrand) {
        Integer id = marketBrand.getId();
        brandMapper.deleteByPrimaryKey(id);

        return true;
    }


}
